#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;
struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
struct Node
{
    TreeNode *ptr;
    int color;
    Node(int color = 0, TreeNode *ptr = nullptr) : color(color), ptr(ptr){};
};
class Solution
{
public:
    enum
    {
        WHITE = 0,
        GRAY = 1
    };
    vector<int> postorderTraversal(TreeNode *root)
    {
        stack<Node> stk;
        vector<int> ans;
        Node nd(WHITE, root);
        stk.push(nd);
        while (stk.empty() == false)
        {
            nd = stk.top();
            stk.pop();
            if (nd.ptr == nullptr)
                continue;
            if (nd.color == WHITE)
            {
                stk.emplace(GRAY, nd.ptr);
                stk.emplace(WHITE, nd.ptr->right);
                stk.emplace(WHITE, nd.ptr->left);
            }
            else
                ans.push_back(nd.ptr->val);
        }
        return ans;
    }
};
int main()
{
    return 0;
}